﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace OMC.Utils
{
    /// <summary>
    /// Logger Utilities.
    /// </summary>
    public static class LoggerUtils
    {
        private const int DefaultPriority = -1;                                         // same as LoggerWriter.DefaultPriority
        private const TraceEventType DefaultSeverity = TraceEventType.Information;      // same as LoggerWriter.DefaultSeverity
        private const int DefaultEventId = 1;                                           // "
        private const string DefaultTitle = "";                                         // "
        private static readonly ICollection<string> emptyCategoriesList = new string[0];

        /// <summary>
        /// Write a new log entry with a specific severity. 
        /// </summary>
        /// <param name="message">Message body to log. Value from ToString() method from message object.</param>
        /// <param name="severity">Log entry severity as a TraceEventType enumeration. (Unspecified, Information, Warning or Error).</param>
        public static void Write(Object message, TraceEventType severity) {
            Logger.Write(message, emptyCategoriesList, DefaultPriority, DefaultEventId, severity, DefaultTitle);
        }

        /// <summary>
        /// Write a new log entry with a specific severity. 
        /// </summary>
        /// <param name="message">Message body to log. Value from ToString() method from message object.</param>
        /// <param name="ex">Exception to log.</param>
        /// <param name="severity">Log entry severity as a TraceEventType enumeration. (Unspecified, Information, Warning or Error).</param>
        public static void Write(Object message, Exception ex, TraceEventType severity)
        {
            Logger.Write(message + "\n" + ex.Message + "\n" + ex.StackTrace.ToString(), emptyCategoriesList, DefaultPriority, DefaultEventId, severity, DefaultTitle);
        }

    }
}
